// pages/ucenter/changemobile/changemobile.js
import * as API_Members from '../../api/members.js'


Page({
	data: {
	  showWxAuth: true
	},
	onLoad(options) {
		if (wx.getStorageSync('refresh_token')) {
		  this.setData({ showWxAuth:  true})
		} else {
		  this.setData({ showWxAuth: false })
		}
	},
  goYEPassword() {
    if (!this.isLogin()) return
    wx.navigateTo({ url: './balance-password/balance-password' })
  },
  /*  goPassword() {
     wx.navigateTo({ url: './changepassword/changepassword' })
   },
   goMobile() {
     wx.navigateTo({ url: './changemobile/changemobile' })
   },
   goEmail() {
     wx.navigateTo({ url: './changeemail/changeemail' })
   }, */
  // 我的足迹
  goFootprint() {
    if (!this.isLogin()) return
    wx.navigateTo({
      url: '/ucenter/my-footprint/my-footprint'
    })
  },
  // 站内消息
  goMessage() {
    if (!this.isLogin()) return
    wx.navigateTo({
      /* url: '/ucenter/site-message/site-message' */
      url: '/ucenter/site-message/website-message/website-message'
    })
  },
  //我的评论
  goComments() {
    if (!this.isLogin()) return
    wx.navigateTo({
      url: '/ucenter/my-comments/my-comments'
    })
  },
  // 我的资料 
  goProfile() {
    if (!this.isLogin()) return
    wx.navigateTo({
      url: "/ucenter/my-profile/my-profile"
    })
  },
  isLogin() {
    if (!wx.getStorageSync('refresh_token')) {
      wx.navigateTo({
        url: '/pages/auth/login/login'
      })
    } else {
      return true
    }
  },
  // 退出登录
  exitLogin() {
    API_Members.getUserInfo().then(response => {
      if (response) {
        wx.showModal({
          title: '提示',
          confirmColor: '#f42424',
          content: '确定要退出登录吗？这将会解绑您的微信！',
          success(res) {
            if (res.confirm) {
              API_Members.logout().then(() => {
                wx.removeStorageSync('access_token')
                wx.removeStorageSync('refresh_token')
                wx.removeStorageSync('uid')
                wx.removeStorageSync('user')
                wx.removeStorageSync('login_result')
                wx.removeStorageSync('daifenrun')
                wx.removeStorageSync('oucoin')
                wx.removeStorageSync('can_rebate')
                wx.removeStorageSync('shoplist')
                // wx.removeStorageSync('qrId')
                wx.switchTab({
                  url: '/pages/home/home'
                })
              }).catch()
            }
          }
        })
      }
    })
  }
})